package com.saifan.wyy_ov.utils;

import java.io.File;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.saifan.wyy_ov.R;
import com.saifan.wyy_ov.config.Api;
import com.saifan.wyy_ov.ui.view.CircleTransform;
import com.squareup.picasso.Picasso;

/**
 * 图片下载类
 *
 * @author wangli
 *
 */
public class ImgUtil {

	/**
	 * @MethodName: DisPlayImg
	 * @Description: 正常网络图片
	 * @param Url
	 * @param img
	 * @param context
	 */
	public static void DisPlayImg(String Url, ImageView img, Context context) {
		if (TextUtils.isEmpty(Url)){
			Picasso.with(context).load(R.drawable.pic_none)  .resize(200, 200).centerCrop().into(img);
		}else {
			Picasso.with(context).load(Api.getUrlIp()  + Url).placeholder(R.drawable.pic_loading).error(R.drawable.pic_load_fail) .resize(200, 200).centerCrop().into(img);
		}


	}
	/**
	 * @MethodName: DisPlayImg
	 * @Description: 正常网络图片
	 * @param file
	 * @param img
	 * @param context
	 */
	public static void DisPlayImg(File file, ImageView img, Context context) {

		Picasso.with(context).load(file).placeholder(R.drawable.pic_none).error(R.drawable.pic_load_fail) .resize(200, 200).centerCrop().into(img);

	}

	/**
	 * @MethodName: DisPlayImg
	 * @Description: 正常网络图片
	 * @param rousceId
	 * @param img
	 * @param context
	 */
	public static void DisPlayImg(int rousceId, ImageView img, Context context) {

		Picasso.with(context).load(rousceId).placeholder(R.drawable.pic_none).error(R.drawable.pic_load_fail) .resize(200, 200).centerCrop().into(img);

	}

	/**
	 * @MethodName: DisPlayImg
	 * @Description: 本地网络图片
	 * @param uri
	 * @param img
	 * @param context
	 */
	public static void DisPlayImgForLocal(String uri, ImageView img, Context context) {

		Picasso.with(context).load("file://"+uri).placeholder(R.drawable.pic_none).error(R.drawable.pic_load_fail) .resize(200, 200).centerCrop().transform(new CropSquareTransformation()).into(img);

	}

	/**
	 * @MethodName: DisPlayRoundImg
	 * @Description: 圆角图片
	 * @param Url
	 * @param img
	 * @param context
	 */
	public static void DisPlayRoundImg(String Url, ImageView img, Context context) {


		Picasso.with(context).load(Url).placeholder(R.drawable.pic_none).error(R.drawable.pic_load_fail) .resize(200, 200).centerCrop().transform(new CircleTransform()).into(img);


	}




}
